<template>
  <div class="info" v-cloak>
    <div v-if=" order.length == 0 ">
      还没有任何订单哦~    快去下单吧
    </div>
    <div class="order-item" v-for="(item,index) in order" v-else>
      <div class="item-head">
        <p class="time">{{item.create_time}}</p>
        <p class="ordernum">订单号：{{item.order_number}}</p>
        <div class="item-head-right">
          
          <div class="a" @click="subbutton(item.order_number,item.total+item.mail)" v-if="item.status == 0"><el-button size="mini" class="go" type="danger">去付款</el-button></div>
          <el-button size="mini" class="del" @click="del(index,item.order_number)">删除订单</el-button>
          <p class="p-zje">总金额：￥<span>{{item.total}}</span></p>
        </div>
      </div>
      <div class="item-mid">
        <div class="td">商品</div>
        <div class="td">单价</div>
        <div class="td">数量</div>
        <div class="td">实付金额</div>
        <div class="td">交易状态</div>
      </div>
      <div class="item-body">
        <div class="list" v-for="i in item.goods_item">
          <div class="td">
            <img :src="comimgsrc+i.preview" alt="">
            <div class="name">
              {{i.name}}
            </div>
          </div>
          <div class="td">
            {{i.price}}/{{i.unit}}
          </div>
          <div class="td">
            {{i.quantity}}
          </div>
          <div class="td">
            {{i.total}}
          </div>
          <div class="td last-td">
            <p v-if="item.pay_status == 0">未支付</p>
            <p v-if="item.pay_status == 1">已支付</p>
            <!-- to="/person/comment" -->
            <div v-if="item.pay_status == 1">
              <div class="a" v-if="i.content_type == 0 && item.status == 2">
                <el-button size="mini" class="go" type="success"  @click="gopl(i.g_id,item.order_number)">
                  去评论
                </el-button>
              </div>
              <div class="a" v-if="i.content_type == 1 && item.status == 2">
                <el-button size="mini" class="go" type="success" disabled>已评论</el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="compage">
          <span @click="syy()"><p>上一页</p></span>
          <span :class="page == n ? 'active':''" v-for="n in last_page" @click="pageon(n)"><p>{{n}}</p></span>
          <span @click="xyy()"><p>下一页</p></span>
        </div>
  </div>
</template>

<script>
import cp1 from '@/assets/image/cp1.jpg';
import qs from "qs"
import store from '@/vuex/store'
export default {
  name: 'App',
  data(){
    return{
      cp1,
      comimgsrc:'http://api.mountainfreshes.com',
      order:[],
      page:1,
      last_page: 0
    }
  },
  methods:{
    pageon:function(n){
      this.page = n
      this.getorderlist()
    },
    syy:function(){
      if(this.page != 1){
        this.page = this.page -1;
        this.getorderlist()
      }
    },
    xyy:function(){
      if(this.page<this.last_page){
        this.page = this.page +1;
        this.getorderlist()
      }
    },
    getorderlist:function(){
        this.$http.post("/index.php/user/order/notpayorderlist",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  user_id: this.$store.state.userid,
                  page: this.page
              }))
              .then(res => {
                this.order = res.data.row.data
                this.last_page = res.data.row.last_page
                console.log(this.order)
              })
              .catch(error => {
                alert("网络错误")
              });
    },
    del:function(i,num){
      this.$confirm('你将删除该订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http.post("/index.php/user/order/del",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  order_number: num

              }))
              .then(res => {
                console.log(res)
                this.order.splice(i,1);
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              })
              .catch(error => {
                alert("网络错误")
              });
          
          
        }).catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '已取消删除'
          // });          
        });
    },
    gopl:function(id,order_num){
      this.$router.push({ path: '/person/comment',query:{iid: id,ordernum: order_num} })
    },
    subbutton:function(ordernum,zjg){
      this.$router.push({ path: '/buypage',query:{ddh: ordernum,ddjg: zjg} })
    }
  },
  components:{
    
  },
  created(){
    this.getorderlist();
  },
  watch:{
    '$route' (to, from) {
                // this.getinfo()
               //   const toDepth = to.path.split('/').length
                // const fromDepth = from.path.split('/').length
                // this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
                // console.log(to.name)
                // if(to.name == 'myshopcar'){
                //   this.getshopcar();
                //   this.allchecked=false
                // }
                if(to.path == '/person/order/no-order'){
                  this.getorderlist();
                }
              }
  }
}
</script>

<style scoped lang="less">
.order-item{
  width: 100%;
  height: auto;
  zoom: 1;
  margin-top: 20px;
  border: 1px solid #a0a0a0;
  box-sizing: border-box;
  .item-head{
    width: 100%;
    height: 40px;
    border-bottom: 1px solid #d8d8d8;
    line-height: 40px;
    .time{
      font-size: 14px;
      color: #212121;
      line-height: 40px;
      float: left;
      margin-left: 18px;
      font-weight: 700;
    }
    .ordernum{
      font-size: 14px;
      color: #313131;
      line-height: 40px;
      margin-left: 30px;
      float: left;
    }
    .item-head-right{
      float: right;
      .a{
        float: right;
      }
      .del{
        float: right;
        margin-top: 6px;
        margin-right: 30px;
      }
      .go{
        float: right;
        margin-right: 40px;
        margin-top: 6px;
      }
      .p-zje{
        float: right;
        line-height: 40px;
        margin-right: 30px;
        span{
          color: #f31818;
          font-weight: 700;
        }
      }
    }
    
  }
  .item-mid{
    width: 100%;
    height: 40px;
    background: #f2f2f2;
    .td{
      width: 16.666666666666%;
      float: left;
      height: 100%;
      text-align: center;
      line-height: 40px;
      font-size: 16px;
      color: #232323;
      &:first-child{
        width: 33.333333333333%;
      }
    }
  }
  .item-body{
    width: 100%;
    height: auto;
    zoom: 1;
    overflow: hidden;
    margin-top: 8px;
    .list{
      width: 100%;
      height: 132px;
      box-sizing: border-box;
      border-top: 1px solid #d6d6d6;
      border-bottom: 1px solid #d6d6d6;
      margin-bottom: 8px;
      .td{
        width: 16.6666666666%;
        height: 100%;
        float: left;
        text-align: center;
        line-height: 132px;
        color: #232323;
        font-size: 16px;
        img{
          display: block;
          width: 136px;
          height: 110px;
          float: left;
          margin: 10px; 
        }
        .name{
          width: 150px;
          display: table-cell;
          vertical-align:middle;
          text-align: left;
          height: 132px;
          font-size: 14px;
          color: #212121;
        }
        &:first-child{
          width: 33.33333333%;
        }
        
      }
      .last-td{
        line-height: 1;
        p{
          padding-top: 56px;
        }
        .a{
          display: block;
          margin: auto;
          margin-top: 10px;
        }
      }
    } 
  }
}
</style>
